package com.itheima.health.mobile.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mobile/setmeal")
public class SetmealController {
  @Reference
  private SetmealService setmealService;

  @RequestMapping("/getSetmeal")
  public Result getSetmeal(){
    try{
      List<Setmeal> list = setmealService.findAll();
      return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS,list);
    }catch(Exception e){
        e.printStackTrace();
        return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
    }
  }

  @RequestMapping("/findById")
  public Result findById(Integer id){
    System.err.println("id"+id);
    try{
      Setmeal setmeal = setmealService.findById(id);
      return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS,setmeal);
    }catch(Exception e){
      e.printStackTrace();
      return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
    }
  }


}